/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import domain.Userdom;
import domain.Vehiclecar;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

/**
 *
 * @author Alberto
 */
public class VehiclecarDao {

    EntityManager em;
    EntityTransaction tx;

    public VehiclecarDao() {
        em = SingletonDao.getInstance().getEntityManager();
        tx = SingletonDao.getTx();
    }

    public Vehiclecar getVehiclecar(Integer idCar) {
        Vehiclecar n = (Vehiclecar) em.createNativeQuery("select * from vehiclecar as v where v.idCar='" + idCar.intValue() + "'", Vehiclecar.class).getSingleResult();
        return n;
    }

    public List<Vehiclecar> getListVehiclecar(Userdom user){
        List<Vehiclecar> list = em.createNativeQuery("select * from vehiclecar as v where v.userFK='"+user.getNick()+"'", Vehiclecar.class).getResultList();
        return list;
    }

    public void saveVehiclecar(Vehiclecar v) {
        tx.begin();
        em.persist(v);
        tx.commit();
    }

    public void removeVehiclecar(Vehiclecar v) {
        tx.begin();
        em.remove(v);
        tx.commit();
    }


    public void updateVehiclecar(Vehiclecar v){
        tx.begin();
        em.createNativeQuery("update vehiclecar set neumdelizq='"+v.getNeumdelizq()+"', neumdelder='"+v.getNeumdelder()+"', neumtrasizq='"+v.getNeumtrasizq()+"', neumtrasder='"+v.getNeumtrasder()+"', liquidofrenos='"+v.getLiquidofrenos()+"', pastfrendel='"+v.getPastfrendel()+"', pasfrentras='"+v.getPasfrentras()+"', discofreno='"+v.getDiscofreno()+"', sintetico='"+v.getSintetico()+"', semisintetico='"+v.getSemisintetico()+"', mineral='"+v.getMineral()+"', cablebujia='"+v.getCablebujia()+"', bujia='"+v.getBujia()+"', liquidlimpia='"+v.getLiquidlimpia()+"', limpiadel='"+v.getLimpiadel()+"', limpiatras='"+v.getLimpiatras()+"', suspension='"+v.getSuspension()+"', liquidrefrigerante='"+v.getLiquidrefrigerante()+"', filtroaire='"+v.getFiltroaire()+"', bateria='"+v.getBateria()+"', aceitecajacambios='"+v.getAceitecajacambios()+"', correadist='"+v.getCorreadist()+"', filtrocombust='"+v.getFiltrocombust()+"', airbag='"+v.getAirbag()+"', posiciondelizq='"+v.getPosiciondelizq()+"', crucedelizq='"+v.getCrucedelizq()+"', carreteradelizq='"+v.getCarreteradelizq()+"', posiciondelder='"+v.getPosiciondelder()+"', crucedelder='"+v.getCrucedelder()+"', carreteradelder='"+v.getCarreteradelder()+"', posiciontrasizq='"+v.getPosiciontrasizq()+"', crucetrasizq='"+v.getCrucetrasizq()+"', carreteratrasizq='"+v.getCarreteratrasizq()+"', frenotrasizq='"+v.getFrenotrasizq()+"', atrastrasizq='"+v.getAtrastrasizq()+"', posiciontrasder='"+v.getPosiciontrasder()+"', crucetrasder='"+v.getCrucetrasder()+"', carreteratrasder='"+v.getCarreteratrasder()+"', frenotrasder='"+v.getFrenotrasder()+"', atrastrasder='"+v.getAtrastrasder()+"' where idCar='"+v.getIdCar()+"'").executeUpdate();
        tx.commit();
    }





}
